package _spring_test._springutils;

import com._23DesignPattern._structure._proxy.DynamicProxy.IPurchase;
import com._23DesignPattern._structure._proxy.DynamicProxy.LogHandler;
import com._23DesignPattern._structure._proxy.DynamicProxy.PurchaseImpl2;
import org.springframework.util.ClassUtils;

import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class _getMostSpecificMethod {

    public static void main(String[] args) throws NoSuchMethodException {
        IPurchase purchase2 = new PurchaseImpl2();
        LogHandler logHandler2 = new LogHandler(purchase2);
        //根据传入的目标对象信息生成具有对应buy方法的代理类
        IPurchase purchaseProxyObject2 = (IPurchase) Proxy.newProxyInstance(purchase2.getClass().getClassLoader(), purchase2.getClass().getInterfaces(), logHandler2);
        purchaseProxyObject2.buy();

        Class<? extends IPurchase> purchaseClass = purchaseProxyObject2.getClass();
        Method buyMethed = purchaseClass.getDeclaredMethod("buy");
        System.out.println(buyMethed);
        System.out.println(ClassUtils.getMostSpecificMethod(buyMethed, PurchaseImpl2.class));
    }
}
